#		    	M A K U
#	c o m p i l a t i o n    c o n f i g u r a t i o n

# Run "qmake; make; make install" to compile and install the program on Unix systems.
# Optional arguments can tune install paths (as in "qmake PREFIX=$HOME").

contains( MODE, debug ) {
    CONFIG += debug  warn_on
    TARGET = maku_debug
    message( "Configuring for debug only..." )
 }
else {
    contains( MODE, all ) {
	CONFIG += debug_and_release build_all warn_on
	CONFIG(debug, debug|release) {
	    TARGET = maku_debug
	} else {
	    TARGET = maku
	}
    }
    else {
	CONFIG += release warn_on
	TARGET = maku
    }
}

# including GLEW by default which is needed for shader support
GLEW = yes

QT += opengl xml

isEmpty( PREFIX ) {
  PREFIX=/usr
}

#		--  U n i x  --
unix {
  LIBS += -lQGLViewer -lOpenMeshCore -lOpenMeshTools
  MOC_DIR = .moc
  OBJECTS_DIR = .obj
}

#		--  L i n u x  --
linux-g++ {
  system(echo \"$${LITERAL_HASH}ifndef MAKU_CONFIG_H\" > config.h)
  contains( CGAL, yes ) {
    system(echo \"$${LITERAL_HASH}define WITH_CGAL\" >> config.h)
    LIBS += -lCGAL
    HEADERS += boundingspheret.h
    #Patch for CGAL bug found in version v.3.4
    system( dpkg-query -l libcgal-dev | grep " 3\.4 " > /dev/null ) {
      message( Patching CGAL bug found in version 3.4 - using -frounding-math flag )
      QMAKE_CXXFLAGS += -frounding-math
    }
  }
  contains( GLEW, yes ) {
    system( echo \"$${LITERAL_HASH}define WITH_GLEW\" >> config.h )
    LIBS += -lGLEW
    # install shaders
    isEmpty( SHADERS_DIR ) {
      SHADERS_DIR = $${PREFIX}/share/maku
    }
    shaders.path = $${SHADERS_DIR}/shaders
    shaders.files = shaders/*.frag shaders/*.vert
    INSTALLS *= shaders
  }
  system( echo \"$${LITERAL_HASH}endif\" >> config.h )
  HEADERS += config.h
}

#		--  W i n d o w s  --
# Configuration thanks to Sergio Boubillier (http://sergiobobillier.blogspot.com/)
win32 {
  # Can not generate both release and debug at the same time. Modify the following lines
  # acording to the type of generatorion you like:

  CONFIG -= debug
  CONFIG += release

  MOC_DIR = moc
  OBJECTS_DIR = obj

  # The following line has the location and name of the dependency libraries for maku
  # you may need to modify this line to match the location of the libraries on your system.

  LIBS += -LC:\libQGLViewer\2.3.4\QGLViewer -LC:\OpenMesh\lib -LC:\glew\1.5.1\lib -lQGLViewer2 -lOpenMeshCore -lOpenMeshTools

  #begin building config.h for windows
  system(echo $${LITERAL_HASH}ifndef MAKU_CONFIG_H > config.h)
  #TODO add CGAL support.
  contains( GLEW, yes ) {
    system( echo $${LITERAL_HASH}define WITH_GLEW >> config.h )
    LIBS += -lglew32
    # install shaders
    isEmpty( SHADERS_DIR ) {
      SHADERS_DIR = $${PREFIX}/share/maku
    }
    shaders.path = $${SHADERS_DIR}/shaders
    shaders.files = shaders/*.frag shaders/*.vert
    INSTALLS *= shaders
  }
  system( echo $${LITERAL_HASH}endif >> config.h )
  HEADERS += config.h
  #end building config.h for windows

  # You may need to edit the following two lines according to your OpenMesh and GLViewer local installation.
  INCLUDEPATH +=  C:\OpenMesh\src \
                  C:\libQGLViewer\2.3.4

  # The following preprocessor directives have only been tested with Microsoft Visual C++ 2008.
  # Please report any compilation problems if you compile maku with other versions of the compiler.

  win32-msvc {
    DEFINES += _USE_MATH_DEFINES NOMINMAX
  }
  win32-msvc.net {
    DEFINES += _USE_MATH_DEFINES NOMINMAX
  }
  win32-msvc2002 {
    DEFINES += _USE_MATH_DEFINES NOMINMAX
  }
  win32-msvc2003 {
    DEFINES += _USE_MATH_DEFINES NOMINMAX
  }
  win32-msvc2005 {
    DEFINES += _USE_MATH_DEFINES NOMINMAX
  }
  win32-msvc2008 {
    DEFINES += _USE_MATH_DEFINES NOMINMAX
  }
}

DESTDIR = .
TEMPLATE = app

FORMS = guis/mainwindow.ui guis/decimaterdialog.ui guis/shader.ui

HEADERS +=	mainwindow.h \
		viewerdock.h \
		scenet.h \
		scenebase.h \
		viewer.h \
		auxviewer.h \
		simplifiert.h \
		decimaterdialog.h \
		decimateroptions.h \
		shaderdialog.h \
		uniform.h \
		boundingbox.h \
		boundingsphere.h \
		boundingboxt.h                

SOURCES +=	mainwindow.cpp \
		viewerdock.cpp \
		main.cpp \
		scenet.cpp \
		scenebase.cpp \
		viewer.cpp \
		auxviewer.cpp \
		decimaterdialog.cpp \
		shaderdialog.cpp \
		uniform.cpp

RESOURCES = ../rsc/rsc.qrc

INCLUDEPATH += bounding_geometry
DEPENDPATH  += . bounding_geometry

isEmpty( INSTALL_DIR ) {
  INSTALL_DIR = $${PREFIX}/bin
}

target.path = $${INSTALL_DIR}

INSTALLS *= target
